﻿using System.Windows.Browser;
using System.Windows.Media;

namespace SLCanvas
{
    // Implements the CanvasGradient interface
    [ScriptableType]
    public class CanvasGradient
    {
        public CanvasGradient()
        {
            OffsetMinimum = 0;
            OffsetMultiplier = 1;
        }

        public void addColorStop(double offset, string cssColor)
        {
            Color color;
            if ((0.0 <= offset) && (offset <= 1.0) && Utility.ParseCssColor(cssColor, out color))
            {
                GradientBrush.GradientStops.Add(new GradientStop { Offset = OffsetMinimum + (offset * OffsetMultiplier), Color = color });
            }
        }

        internal GradientBrush GradientBrush { get; set; }

        // OffsetMinimum/OffsetMultiplier are used by createRadialGradient to
        // more easily implement its starting/ending radius behavior
        internal double OffsetMinimum { get; set; }
        internal double OffsetMultiplier { get; set; }
    }
}
